package ztp

import (
	"gitee.com/sunny-zhangqiang/zcache_new/comm"
	"io"
)

var (
	be = comm.BE
)

func ReadN(reader io.Reader, buf []byte, todo int) error {
	r := 0

	for {
		p := buf[r:]
		n, err := reader.Read(p)
		if err != nil {
			return err
		}

		r += n
		if r == todo {
			return nil
		}
	}
}

func WriteN(writer io.Writer, buf []byte, todo int) error {
	w := 0

	for {
		p := buf[w:]
		n, err := writer.Write(p)
		if err != nil {
			return err
		}

		w += n
		if w == todo {
			return nil
		}
	}
}
